import { Component, EventEmitter, Injector, Output, OnInit, ViewChild, Input, AfterViewInit } from '@angular/core';
import { AppComponentBase } from '@shared/common/app-component-base';
import { ExecutionPointerDto, ApplyChangeServiceProxy, ApplyChangeMainDto} from '@shared/service-proxies/service-proxies';
import { ModalDirective } from 'ngx-bootstrap';
import * as _ from 'lodash';
import { Paginator } from 'primeng/components/paginator/paginator';
import { Table } from 'primeng/components/table/table';
import { PrimengTableHelper } from 'shared/helpers/PrimengTableHelper';

@Component({
  selector: 'CrucialOutsourcingApplyChangeAudit',
  templateUrl: './CrucialOutsourcingApplyChangeAudit.component.html',
  styleUrls: ['./CrucialOutsourcingApplyChangeAudit.component.css']
})
export class CrucialOutsourcingApplyChangeAuditComponent extends AppComponentBase implements OnInit, AfterViewInit {
  @ViewChild('createOrEditModal') modal: ModalDirective;
  @ViewChild('paginator') paginator: Paginator;
  @ViewChild('dataTable') dataTable: Table;
  @ViewChild('recodedataTable') teskdataTable: Table;

  @Input() workflowid: any;
  @Output() out = new EventEmitter();

  saving = false;
  ApplyChangeDetailsDto;
  _ApplyChangeMainDto: ApplyChangeMainDto = new ApplyChangeMainDto(); 
  detailsprimengTableHelper: PrimengTableHelper;
  constructor(injector: Injector,
    private _applyChangeAppService: ApplyChangeServiceProxy) {
    super(injector);
    this.detailsprimengTableHelper = new PrimengTableHelper();
  }
  ngOnInit(): void {
    console.log(this.workflowid);
    this.initForm();
  }
  ngAfterViewInit() {
    console.log('ngAfterViewInit');
  }

  initForm(): void {
    console.log("initForm");
    this._applyChangeAppService.getOutsourcingApplyChange(this.workflowid).subscribe(dto => {
      this._ApplyChangeMainDto = dto.applyChangeMain;
      this.ApplyChangeDetailsDto = dto.applyChangeDetails;
      console.log(dto);
      this.primengTableHelper.totalRecordsCount = this.ApplyChangeDetailsDto.length;
      this.primengTableHelper.records = this.ApplyChangeDetailsDto;
      this.primengTableHelper.hideLoadingIndicator();
    });
  }

  audityes(): void {
    this._applyChangeAppService.crucialOutsourcingChangeAuditFlow_execute(this.workflowid, 'yes').subscribe(dto => {
      console.log(dto);
      this.out.emit(dto);
    });
  }

  auditno(): void {
    this._applyChangeAppService.crucialOutsourcingChangeAuditFlow_execute(this.workflowid, 'no').subscribe(dto => {
      console.log(dto);
      this.out.emit(dto);
    });
  }
 
  getAuditName(item: ExecutionPointerDto) {
    return item.extensionAttributes.Prompt;
  }
}
